# -*- coding:utf-8 -*-
from datetime import date, datetime
import calendar


class Person(object):  # 新式类
    def __init__(self, birth_date, name, city):
        self.birth_date = birth_date
        self.name = name
        self.city = city
        self.__sex = None

    @property
    def sex(self):
        return self.__sex

    @sex.setter
    def sex(self, value):
        if not isinstance(value, str):
            raise ValueError("Expected a string")
        self.__sex = value

    @staticmethod
    def calculate_leap_days(start_date, end_date):
        if isinstance(start_date, date) and isinstance(end_date, date):
            start_year = start_date.year
            end_year = end_date.year
            leap_days = calendar.leapdays(start_year, end_year)  # 计算之间的闰年天数，不包括结束年份
            print leap_days
            return leap_days

        else:
            return None

    def get_age(self):
        birth_date = self.birth_date
        now_date = datetime.now().date()
        if isinstance(birth_date, (date, datetime)):
            delta_days = now_date - birth_date
        else:
            birth_date = datetime.strptime(self.birth_date, "%Y-%m-%d").date()

            delta_days = now_date - birth_date

        fixed_delta_days = delta_days.days - self.calculate_leap_days(birth_date, now_date)
        print fixed_delta_days
        return int(fixed_delta_days / 365)


class Student(Person):
    def __init__(self, birth_date, name, city, stu_id):
        Person.__init__(self, birth_date, name, city)
        self.stu_id = stu_id


# a_person = Person(name='tom', birth_date='2016-08-09')

a_student = Student(name='aa', birth_date='1990-08-30', stu_id=001,city='Beijing')
a_student.sex = 'female'

print a_student.get_age()
print a_student.stu_id
print a_student.city
